package com.project.config;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.handler.annotation.Header;

import java.io.IOException;


@Configuration
public class RabbitConfig {
    @Autowired
    CachingConnectionFactory connectionFactory;
    //rabbitmq模板
    @Bean(value = "rabbitTemplate")
    public RabbitTemplate rabbitTemplate(){
        return new RabbitTemplate(connectionFactory);
    }

    //创建公共交换机----------------------------------------------------------
    @Bean
    public TopicExchange topicExchangeTwo(){
        return new TopicExchange("topicExchangeTwo");
    }


    /*
     * 供应商队列----------------------------------------------------------------
     */
    /**
     * @return  供应商注册审核结果
     */
    @Bean
    public Queue SupplierVerifyResult(){
        return new Queue("SupplierVerifyResult");
    }
    @Bean
    public Binding SupplierVerifyResultBind(@Value("SupplierVerifyResult") Queue SupplierVerifyResult, TopicExchange topicExchangeTwo){
        return   BindingBuilder.bind(SupplierVerifyResult).to(topicExchangeTwo).with("rabbit.SupplierVerifyResult");
    }


    /**
     * @return  客户注册审核结果
     */
    @Bean
    public Queue UserVerifyResult(){
        return new Queue("UserVerifyResult");
    }
    @Bean
    public Binding UserVerifyResultBind(@Value("UserVerifyResult") Queue UserVerifyResult, TopicExchange topicExchangeTwo){
        return   BindingBuilder.bind(UserVerifyResult).to(topicExchangeTwo).with("rabbit.UserVerifyResult");
    }

    /**
     * @return  客户注册成功给后端发送用户
     */
    @Bean
    public Queue UserVerifySuccess(){
        return new Queue("UserVerifySuccess");
    }
    @Bean
    public Binding UserVerifySuccessBind(@Value("UserVerifySuccess") Queue UserVerifySuccess, TopicExchange topicExchangeTwo){
        return   BindingBuilder.bind(UserVerifySuccess).to(topicExchangeTwo).with("rabbit.UserVerifySuccess");
    }



    //交换机与队列绑定----------------------------------------------------------
    /**
     * @return  招标书发送
     */
    @Bean
    public Queue BiddSender(){
        return new Queue("BiddSender");
    }
    @Bean
    public Binding BiddSenderBind( Queue BiddSender, TopicExchange topicExchangeTwo){
        return   BindingBuilder.bind(BiddSender).to(topicExchangeTwo).with("rabbit.BiddSender");
    }


    /**
     * @return  供应商投标申请审核结果（中标确认结果）
     */
    @Bean
    public Queue TenderVerifyResult(){
        return new Queue("TenderVerifyResult");
    }
    @Bean
    public Binding TenderVerifyResultBind( Queue TenderVerifyResult, TopicExchange topicExchangeTwo){
        return   BindingBuilder.bind(TenderVerifyResult).to(topicExchangeTwo).with("rabbit.TenderVerifyResult");
    }





//    //交换机与队列绑定----------------------------------------------------------
    /**
     * @return  促销方案审核结果
     */
    @Bean
    public Queue PromotionVerifyResult(){
        return new Queue("PromotionVerifyResult");
    }
    @Bean
    public Binding PromotionVerifyResultBind(Queue PromotionVerifyResult, TopicExchange topicExchangeTwo){
        return   BindingBuilder.bind(PromotionVerifyResult).to(topicExchangeTwo).with("rabbit.PromotionVerifyResult");
    }
    //----------------------------------------------------------



    /**
     * @return  用户订单退款审核结果
     */
    @Bean
    public Queue UserOrderRefundSupplierVerifyResult(){
        return new Queue("UserOrderRefundSupplierVerifyResult");
    }
    @Bean
    public Binding UserOrderRefundSupplierVerifyResultBind( Queue UserOrderRefundSupplierVerifyResult, TopicExchange TopicExchange){
        return   BindingBuilder.bind(UserOrderRefundSupplierVerifyResult).to(TopicExchange).with("rabbit.UserOrderRefundSupplierVerifyResult");
    }





    /**
     * @return  采购申请审核结果
     */
    @Bean
    public Queue ProcureApplySupplierVerifyResult(){
        return new Queue("ProcureApplySupplierVerifyResult");
    }
    @Bean
    public Binding ProcureApplySupplierVerifyResultBind( Queue ProcureApplySupplierVerifyResult, TopicExchange TopicExchange){
        return   BindingBuilder.bind(ProcureApplySupplierVerifyResult).to(TopicExchange).with("rabbit.ProcureApplySupplierVerifyResult");
    }




    /**
     * @return  后端给供应商退货单审核结果
     */
    @Bean
    public Queue SupplyOrderRefundSupplierVerifyResult(){
        return new Queue("SupplyOrderRefundSupplierVerifyResult");
    }

    @Bean
    public Binding SupplyOrderRefundSupplierVerifyResultBind( Queue SupplyOrderRefundSupplierVerifyResult, TopicExchange topicExchangeTwo){
        return   BindingBuilder.bind(SupplyOrderRefundSupplierVerifyResult).to(topicExchangeTwo).with("rabbit.SupplyOrderRefundSupplierVerifyResult");
    }


    /**
     * @return  发送给供应商退货订单
     */
    @Bean
    public Queue SupplyOrderRefundOrder(){
        return new Queue("SupplyOrderRefundOrder");
    }

    @Bean
    public Binding SupplyOrderRefundOrderBind( Queue SupplyOrderRefundOrder, TopicExchange topicExchangeTwo){
        return   BindingBuilder.bind(SupplyOrderRefundOrder).to(topicExchangeTwo).with("rabbit.SupplyOrderRefundOrder");
    }


    /**
     * 发送供应商供货单
     */
    @Bean
    public Queue sendSupplyOrder(){
        return new Queue("sendSupplyOrder");
    }
    @Bean
    public Binding sendSupplyOrderBind( Queue sendSupplyOrder, TopicExchange topicExchangeTwo){
        return   BindingBuilder.bind(sendSupplyOrder).to(topicExchangeTwo).with("rabbit.sendSupplyOrder");
    }


    /**
     * 发送给后端客户退货
     */
    @Bean
    public Queue sendUserRefundOrder(){
        return new Queue("sendUserRefundOrder");
    }
    @Bean
    public Binding sendUserRefundOrderBind( Queue sendUserRefundOrder, TopicExchange topicExchangeTwo){
        return   BindingBuilder.bind(sendUserRefundOrder).to(topicExchangeTwo).with("rabbit.sendUserRefundOrder");
    }


}
